package com.chouxiaozi.controller;

import com.chouxiaozi.feignclient.PaymentClient;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@DefaultProperties(defaultFallback="defaultFallback") //默认降级
@RequestMapping("/consumer")
public class PaymentController {

    @Autowired
    PaymentClient paymentClient;

    @GetMapping("/payment_ok")
    public String payment_ok(){
        return paymentClient.payment_ok();
    }

    @GetMapping("/payment_timeout")
    public String payment_timeout(){
        return paymentClient.payment_timeout();
    }

    /**新增降级处理方法*/
    public String payment_timeoutFallBack(){
        return "consumer80:payment_timeoutFallBack: "+Thread.currentThread().getName()+" >>>service is busy";
    }

    @GetMapping("/payment_error")
    @HystrixCommand
    public String error(){//不指定降级方法
        int i = 1/0;
        return "";
    }

    @GetMapping("/payment_error2")
    public String error2(){//不配置降级
        int i = 1/0;
        return "";
    }

    /**默认降级处理方法*/
    public String defaultFallback(){
        return "consumer80:defaultFallback: "+Thread.currentThread().getName()+" >>>service is busy";
    }
}
